layui.use(['form', 'layer','jquery'], function () {
    $ = layui.jquery;
    var form = layui.form;
    var layer = layui.layer;

    //自定义验证规则
    form.verify({
        L_url: [/(\/.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/, "请输入正确路径！"],
    })

    //监听提交
    form.on('submit(add)', function (data) {
        // console.log(data.field);
        //发异步，把数据提交给Java 添加导航
        $.ajax({
            type: 'post',
            url: requestURL+prefix+elseService+'/nav/save',
            headers: {"Authorization":authToken},
            data: JSON.stringify(data.field),
            contentType: 'application/json;charset=utf-8',
            dataType: 'json',
            success: function (res) {
                if (res.status == 200) {
                    $("#sumbit").attr("disabled",true); //禁止点击按钮
                    layer.msg('添加成功！', {icon: 1, time: 1100,end:function () {
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        }});
                    return false;
                }
                layer.msg('添加失败！', {icon: 2, time: 1200});
                return false;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var state = XMLHttpRequest.status;
                if (state == 403) {
                    layui.layer.msg('权限不足，请联系超级管理员！', {icon: 0, time: 1200});
                    return false;
                }
                layui.layer.msg('请求接口异常！', {icon: 0, time: 1200});
                return false;
            }

        });
        return false;
    });

});